package com.cy.law.vo;


public enum CodeMessage {
    UNDEFINED(-1, "未定义!"),
    UNKNOWN_ERROR(-2, "未知错误!"),
    SUCCESS(0, "成功!"),
    WRONG_USER_PSW(1, "错误的用户名或密码!"),
    UNAUTHORIZED(2, "当前用户未授权或登录失效,请重新登录!"),
    PASSWORD_NULL_ERROR(3, "登录密码不能为空!"),
    CANNOT_FIND_HUMAN(4, "无法找到相应用户!"),
    ALREADY_LOGIN(5, "用户已登录,ip:%s"),
    CAN_NOT_FIND_HUMAN_IN_CAHCE(6, "无法获取用户!"),

    // save
    SAVE_SUCCESS(0, "保存成功!"),
    SAVE_FAILED(11, "保存失败!"),
    // delete
    DELETE_SUCCESS(0, "删除成功!"),
    DELETE_FAILED(12, "删除失败!"),
    // wf
//    UNAUTHORIZED(100,"当前用户未授权"),
    CONFIRM_SUCCESS(0, "确认成功"),
    AUDITING_SUCCESS(0, "审核成功!"),
    CONFIRM_FAILED(101, "确认失败!"),
    AUDITING_FAILED(102, "审核失败!"),

    // unit
    DUPLICATE_UNIT_NAME(101, "重复的部门名字!"),

    //human
    DUPLICATE_HUMAN_NAME(201, "重复的人员名字!");

    private int code;
    private String message;

    CodeMessage(int code, String message) {
        this.code = code;
        this.message = message;
    }

    public int getCode() {
        return code;
    }

    private void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    private void setMessage(String message) {
        this.message = message;
    }

    public static String msgOf(int code) {
        for (CodeMessage cm : CodeMessage.values()) {
            if (cm.getCode() == code) {
                return cm.getMessage();
            }
        }
        return null;
    }

    public static CodeMessage typeOf(int code) {
        for (CodeMessage cm : CodeMessage.values()) {
            if (cm.getCode() == code) {
                return cm;
            }
        }
        return null;
    }
}